package com.start.dataSource.entity;

import com.alibaba.fastjson2.JSONObject;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;


@Data
@EqualsAndHashCode(callSuper = true)
public class StartGenTableColumn extends StartTableColumn {
    /**
     * 驼峰属性
     */
    private String caseAttrName;
    /**
     * 普通属性
     */
    private String lowerAttrName;
    /**
     * 属性类型
     */
    private String attrType;

    /**
     * 属性名称
     */
    private String attrName;

    private JSONObject startColumnOption;

    private boolean isAddEntity = true;


    public void createOption() {
        if (StringUtils.isEmpty(this.getColumnComment())) {
            this.setColumnComment(this.getColumnName());
        }
        StartColumnOption startColumnOption = new StartColumnOption();
        startColumnOption.setLabel(getColumnComment());
        startColumnOption.setType(getOptionType(getColumnType()));
        startColumnOption.setProp(attrName);
        switch (attrName) {
            case "createBy":
            case "updateBy":
            case "updateTime":
            case "createTime":
            case "id":
                startColumnOption.setAddDisplay(false);
                startColumnOption.setEditDisplay(false);
                startColumnOption.setShowColumn(false);
                this.setAddEntity(false);
                break;

        }
        this.startColumnOption = (JSONObject) JSONObject.from(startColumnOption);
    }

    public static String getOptionType(String columnType) {
        switch (columnType) {
            case "int":
            case "bigint":
            case "float":
            case "double":
            case "bit":
                return "number";
            case "date":
            case "datetime":
            case "timestamp":
                return "datetime";
            default:
                return "input";
        }
    }

}
